﻿@model PessMvc.Models.UserModel

@{
    ViewBag.Title = "EditAuthorInfo";
}

<h2>Edit Author Info</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset class="edit">
        <legend></legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.DisplayFor(model => model.UserName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PhoneNumber)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PhoneNumber)
            @Html.ValidationMessageFor(model => model.PhoneNumber)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Fax)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Fax)
            @Html.ValidationMessageFor(model => model.Fax)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SchoolName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SchoolName)
            @Html.ValidationMessageFor(model => model.SchoolName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Address1)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Address1)
            @Html.ValidationMessageFor(model => model.Address1)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Address2)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Address2)
            @Html.ValidationMessageFor(model => model.Address2)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.StateProvince)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.StateProvince)
            @Html.ValidationMessageFor(model => model.StateProvince)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ZipCode)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ZipCode)
            @Html.ValidationMessageFor(model => model.ZipCode)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Country)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Country)
            @Html.ValidationMessageFor(model => model.Country)
        </div>

        @Html.HiddenFor(model=>model.UserName)
        @Html.HiddenFor(model => model.Email)

        <div class="editor-btn">
            <input type="submit" value="Save" />
        </div>
    </fieldset>
}

<div id="dialog-message" title="Message">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;">Message</span>
        <span id="msg_in_dialog"></span>
    </p>
</div>

<script type="text/javascript">
          $(document).ready(function () {

         $("#dialog-message").hide();

          $("form").submit(function (event) {
              event.preventDefault();
              $(this).validate().defaultShowErrors();
              if ($(this).valid()) {
                  // Show the "busy" Gif:
                  $('#msg_in_dialog').html("Processing...<br/><br/><img src='@Url.Content("~/images/ajax-loader.gif")'>");
                  $("#dialog-message").dialog({
                      modal: true
                  });

                  var url = $(this).attr("action");
                  var formData = $(this).serialize();
                  $.ajax({
                      url: url,
                      type: "POST",
                      data: formData,
                      dataType: "json",
                      success: function (url) {
                          // Hide the "busy" gif:
                          $('#msg_in_dialog').html("Changes saved.");
                          $("#dialog-message").dialog({
                              modal: true,
                              buttons: {
                                  "OK": function () {
                                      window.location.href = url;
                                      $(this).dialog("close");

                                  }
                              }
                          });
                          // Do something useful with the data:
                      }
                  })
              }
              else
              {
                  //$(".error").show();
                  //$('#msg_in_dialog').html("Please complete all the fields.");
                  //$("#dialog-message").dialog({
                  //    modal: true,
                  //    buttons: {
                  //        "Close": function () {
                  //            $(this).dialog("close");
                  //        }
                  //    }
                  //});
              }
          });

  });

</script>

